package com.example.demo.controller;

import com.example.demo.pojo.Order;
import com.example.demo.pojo.Signin;
import com.example.demo.service.SigninService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/signin")
public class SigninController {
    @Autowired
    private SigninService signinService;

    //签到
    @PostMapping("/addSignin")
    public Object addSignin(@RequestBody Signin signin) {
        HashMap<String, Object> map = new HashMap();
        int i = signinService.addSignin(signin);
        if (i > 0) {
            map.put("code", 200);
            map.put("msg", "签到成功");
        } else {
            map.put("code", 300);
            map.put("msg", "签到失败");
        }
        return map;
    }

    //查询签到记录
    @GetMapping("/query")
    public Object query(@RequestParam("userid") String userid) {
        HashMap<String, Object> map = new HashMap();
        List<Signin> list = signinService.query(userid);
        if (list.size() > 0) {
            map.put("code", 200);
            map.put("msg", "签到列表查询成功");
            map.put("data", list);
        } else {
            map.put("code", 300);
            map.put("msg", "签到列表查询失败");
        }
        return map;
    }
}
